var supplierObj = [];
var limit = 30;var proTypeObj = convertEnumToObj(proTypeList); var todoTimer;
layui.use(['laypage', 'table', 'form', 'laydate'], function(){
    var table = layui.table,laydate = layui.laydate,util = layui.util,form = layui.form,element = layui.element;
    laydate.render({
        elem: '#search-startTime',
        type: 'datetime',
        done: function(value, date, endDate){

        }
    });
    laydate.render({
        elem: '#search-endTime',
        type: 'datetime',
        done: function(value, date, endDate){

        }
    });

    let todoCols = [
        [
            {field: 'id', title: '标识', width:80, align: 'center', hide: true}
            ,{field: 'code', title: '任务单号', width:160, align: 'center',sort:true}
            ,{field: 'conName', title: '工程名称', width:220, align: 'center',sort:true}
            ,{field: 'site', title: '施工部位', width: 160, align: 'center',sort:true}
            ,{field: 'type', title: '状态', width:80, align: 'center',sort:true, templet:function (val){
                var type = val.type;
                if (type != null)
                    return proTypeObj[type];
                return '';
            }}
            ,{field: 'strengthName', title: '强度等级', width:100, align: 'center',sort:true}
            ,{field: 'tech', title: '特性', width:100, align: 'center',sort:true}
            ,{field: 'lineCode', title: '配比保存状态', width:140, align: 'center', templet:function (val) {
                var lineCode_ = val.lineCode;
                if (lineCode_ != null) {
                    var lineCode = lineCode_.split(',');
                    if (lineCode != null && lineCode_.length > 0) {
                        var str = '';
                        $.each(lineCode, function (i, v) {
                            str += '<a href="javascript:void(0)" class="layui-btn layui-btn-sm layui-btn-xs" style="background: #009688;">' + v + '</a>';
                        });
                        return  str;
                    }
                }
                return '';
            }}
            ,{field: 'lineCode', title: '配比上传状态', width:140, align: 'center', templet:function (val) {
                var isUpload_ = val.isUpload;
                var lineCode_ = val.lineCode;
                if (lineCode_ != null) {
                    var lineCode = lineCode_.split(',');
                    var isUpload = isUpload_.split(',');
                    if (lineCode != null && lineCode_.length > 0) {
                        var str = '';
                        $.each(lineCode, function (i, v) {
                            if (isUpload != null) {
                                if (isUpload[i] == 1)
                                    str += '<a href="javascript:void(0)" class="layui-btn layui-btn-sm layui-btn-xs" style="background: #009688;">' + v + '</a>';
                                else
                                    str += '<a href="javascript:void(0)" class="layui-btn layui-btn-sm layui-btn-xs" style="background: #ff5722;">' + v + '</a>';
                            }
                        });
                        return  str;
                    }
                }
                return '';
            }}
            ,{field: 'distance', title: '运距', width:80, align: 'center',sort:true}
            ,{field: 'castModelName', title: '浇筑方式', width:100, align: 'center',sort:true}
            ,{field: 'clientName', title: '客户名称', width: 160, align: 'center',sort:true}
            ,{field: 'slumps', title: '坍落度', width:90, align: 'center',sort:true}
            ,{field: 'dispatchStartTime', title: '计划开盘时间', width:130, align: 'center',sort:true}
            ,{field: 'actualStartTime', title: '实际开盘时间', width:130, align: 'center',sort:true}
            ,{field: 'planStere', title: '计划方量', width:90, align: 'center',sort:true}
            ,{field: 'sendStere', title: '累计发货', width:90, align: 'center',sort:true}
            ,{field: 'conCode', title: '合同编号', width:140, align: 'center'}
            ,{field: 'status', title: '状态', width:80, align: 'center', templet:function (val) {
                if (val.status == 0)
                    return '启用';
                else
                    return '禁用';
            }}
            ,{field: 'remark', title: '备注', width: 200, align: 'center'}
            ,{fixed: 'right', title:'操作', width: 120, align:'center', templet:function (val) {
                var str = '<a lay-event="upload" href="javascript:void(0)" class="layui-btn layui-btn-xs">详情</a>';
                return str;
            }}
        ]
    ];

    table.render({
        elem: '#body-list'
        ,url: '/lab/expend-upload/page'
        ,method: 'post'
        ,page: true
        ,cols: todoCols
        ,limit: limit
        ,height:800
        ,limits: [30,50,100]
        ,request: {
            pageName: 'curr' //页码的参数名称，默认：page
            ,limitName: 'limit' //每页数据量的参数名，默认：limit
        }
        ,where: {
            offset: 0,
            limit: limit
        }
        ,parseData: function(res){ //res 即为原始返回的数据
            console.log(res)
            if (res.code == 0 && res.data != null) {
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            } else {
                return {
                    "code": res.code, //解析接口状态
                    "msg": '没有任何数据', //解析提示文本
                    "count": 0, //解析数据长度
                    "data": '' //解析数据列表
                };
            }
        }
    });

    //监听行工具事件
    table.on('tool(body-list)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data //获得当前行数据
            ,layEvent = obj.event; //获得 lay-event 对应的值
        if(layEvent === 'upload'){
            updateWindow(data);
            form.render(data);
        }
    });
    table.on('rowDouble(body-list)', function(obj){
        var data = obj.data;
        updateWindow(data);
    });
    form.on('select(search-proType)', function(data) {
        $(".btn-query").trigger("click");
    });
    form.on('select(search-uploadType)', function(data) {
        $(".btn-query").trigger("click");
    });
    form.on('select(search-origin)', function(data) {
        $(".btn-query").trigger("click");
    });

    $('.btn-query').on('click', function () {//搜索按钮
        var searchVal = $('.search-text').val();
        var orgId = $('.search-origin').val();
        var proType = $('.search-proType').val();
        var isUpload = $('.search-uploadType').val();
        var option = {page:1,limit:limit};
        if (!isNull(searchVal))
            option['searchVal'] = searchVal;
        if (!isNull(proType))
            option['proType'] = proType;
        if (!isNull(orgId))
            option['orgId'] = orgId;
        if (isUpload != null)
            option['isUpload'] = isUpload;
        // console.log(option)
        table.reload('body-list', {
            where: option,page:{curr:1}
        });
    });
    function updateWindow(data) {
        console.log(data)
        var title = data.site + '---' + data.strengthName;
        layer.open({
            type: 2,
            title: '(' + data.code + ')' + data.clientName + '[' + data.conName + ']--->'  + title,
            shade: 0.1,
            area: ['100%', '100%'],
            maxmin: true,
            // area: 'auto',
            content: ['/console/lal-level/history-expend-detail?indentId=' + data.id, 'yes']
        });
    }
});